<template>
    <div>
        <h1>编辑</h1>
        <table class="table">
            <tbody>
                <tr>
                    <td>编号</td>
                    <td>
                        <input type="text" disabled v-model="date.houseId">
                    </td>
                </tr>
                <tr>
                    <td>房间名称</td>
                    <td>
                        <input type="text" v-model="date.houseName">
                    </td>
                </tr>
                <tr>
                    <td>号</td>
                    <span v-for="a in fanhao">
                        <input type="checkbox" v-model="fannum" :value="a">{{ a }}
                    </span>
                </tr>
                <tr>
                    <td>门市价格</td>
                    <td>
                        <input type="text" v-model="date.price">
                    </td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td>
                        <input type="checkbox" v-model="date.state">勾选为true,否则false
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="button" value="修改" @click="upd">
                    </td>
                </tr>
            </tbody>
        </table>
        <a href="/Show">返回显示列表</a>
    </div>
</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue';
import { useRoute,useRouter } from 'vue-router';
import axios from 'axios';
onMounted(()=>{
    xiu()
})
const routh=useRoute();
const routher=useRouter();

const fanhao=ref(["1001","1002","1003","1004","1005","1006","1007","1008"])
const fannum=ref([])

const xiu=()=>{
    var vid = routh.query.id
    axios.get("https://localhost:7264/api/House/GetHouse",{params:{id:vid}}).then(res=>{
        date.value=res.data;

        fannum.value=date.value.numHao.split(',')
    })
}
const upd=()=>{
    if(date.value.houseName==""){
        alert("名称不能为空")
        return
    }
    if(!confirm("确认修改吗")){
        return
    }
    date.value.numCount=fanhao.value.length
    date.value.numHao=fannum.value.toString()

    axios.put("https://localhost:7264/api/House/UpdHouse",date.value).then(res=>{
        if(res.data>0){
            alert("修改成功")
            routher.push({path:"/Show"})
        }
        else{
            alert("修改失败")
        }
    })
}

const date=ref({
    "houseId": 0,
    "houseName": "",
    "price": 0,
    "numCount": 0,
    "numHao": "",
    "state": null,
    //"isDelete": false
})
</script>

<style scoped>

</style>